#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/4/9 22:54
# @Author : cjw
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from chaojiying import Chaojiying_Client
from time import sleep

if __name__ == '__main__':
    # 不显示自动化软件控制提示
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-automation'])

    driver = webdriver.Chrome(options=options)
    driver.maximize_window()
    driver.get('http://www.chaojiying.com/user/login/')
    img = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//div/img')).screenshot_as_png
    chaojiying = Chaojiying_Client('xxx', 'xxx@', '915032')
    verify_code = chaojiying.PostPic(img, 1902)['pic_str']
    WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//input[@name="user"]')).send_keys('xxx')
    WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//input[@name="pass"]')
                                    ).send_keys('xxx')
    WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//input[@name="imgtxt"]')).send_keys(verify_code)
    sleep(3)
    WebDriverWait(driver, 10).until(lambda x: x.find_element_by_xpath('//input[@type="submit"]')).click()
    sleep(2)
    driver.quit()
